package com.yfp.tissue.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.common.security.annotation.RequiresPermissions;
import com.yfp.tissue.domain.Dto.AreaDto;
import com.yfp.tissue.domain.entity.Area;
import com.yfp.tissue.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @PROJECT_NAME: ydyfp
 * @DESCRIPTION:
 * @USER: xiaohuya
 * @DATE: 2023/12/17 14:49
 */

@RestController
@RequestMapping("/area")
@Tag(name = "区域管理")
public class AreaController extends BaseController {
    @Resource
    private AreaService areaService;

    /**
     * 区域条件
     */
    @GetMapping("conditionsArea")
    @Operation(summary = "条件查询")

    public R conditionsArea(String companyId) {
        startPage();

        return areaService.conditionsArea(companyId);
    }

    /**
     * 区域查询
     */
    @GetMapping("areaList")
    @Operation(summary = "区域查询")
    public TableDataInfo queryArea(@RequestParam(value = "companyId", required = false) String companyId, @RequestParam(value = "areaId", required = false) String areaId, @RequestParam(value = "contracts", required = false) String contracts, @RequestParam(value = "provinceId", required = false) String provinceId, @RequestParam(value = "cityId", required = false) String cityId, @RequestParam(value = "countyId", required = false) String countyId, @RequestParam(value = "contactsName", required = false) String contactsName, @RequestParam(value = "enabled", required = false) String enabled,@RequestParam(value = "cityName", required = false) String cityName) {
        startPage();
        AreaDto areaDto = new AreaDto();
        areaDto.setAreaId(areaId);
        areaDto.setCompanyId(companyId);
        areaDto.setEnabled(enabled);
        areaDto.setContracts(contracts);
        areaDto.setProvinceId(provinceId);
        areaDto.setCityId(cityId);
        areaDto.setCountyId(countyId);
        areaDto.setContactsName(contactsName);
        areaDto.setCityName(cityName);
        return getDataTable(areaService.queryArea(areaDto));
    }

    /**
     * 查询区域详情
     */
    @GetMapping("areaDetail")
    @Operation(summary = "区域详情")

    public R areaDetail(String areaId) {
        return areaService.areaDetail(areaId);
    }

    /**
     * 新增区域
     */
    @PostMapping("addArea")
    @Operation(summary = "新增区域")
    @Log(title = "新增区域", businessType = BusinessType.INSERT)
    @RequiresPermissions("tissue:are:add")

    public R addArea(@RequestBody Area area) {
        return areaService.addArea(area);

    }

    /**
     * 修改区域
     */
    @PostMapping("updateArea")
    @Operation(summary = "修改区域")
    @Log(title = "修改区域", businessType = BusinessType.UPDATE)
    @RequiresPermissions("tissue:are:edit")

    public R updateArea(@RequestBody Area area) {
        return areaService.updateArea(area);

    }


    /**
     * 新增区域查询条件
     */
    @GetMapping("addQuery")
    @Operation(summary = "新增区域查询条件")
    @RequiresPermissions("tissue:are:query")

    public R addQuery(String companyId) {
        return areaService.addQuery(companyId);

    }


    /**
     * 禁用
     */
    @GetMapping("areaProhibit")
    @Log(title = "禁用", businessType = BusinessType.UPDATE)
    @Operation(summary = "禁用")
    @RequiresPermissions("tissue:are:dis")

    public R addQuery(String id, String enabled) {
        return areaService.prohibit(id, "区域", enabled);

    }
}
